<template>
  <div>
    <!--过滤条件-->
    <el-form size="mini">
      <el-row :gutter="20">
        <el-col style="width: 280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">下单日期:</div>
          <el-date-picker v-model="filterData.daterange" type="daterange" align="right" unlink-panels
            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
            value-format="yyyy-MM-dd" :picker-options="pickerOptions">
          </el-date-picker>
        </el-col>
        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">订单渠道:</div>
          <el-select v-model="filterData.platform" style="width: 100%;" placeholder="订单渠道" clearable filterable multiple>
            <el-option v-for="(item,index) in platforms" :label="item.label" :key="item.index" :value="item.label">
            </el-option>
          </el-select>
        </el-col>
        <el-col style="width: 280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">外部单号:</div>
          <el-input placeholder="外部单号" v-model="filterData.ordercode" clearable></el-input>
        </el-col>
        <el-col style="width: 280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">内部单号:</div>
          <el-input placeholder="内部单号" v-model="filterData.ouid" clearable></el-input>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">商品名称:</div>
          <el-input v-model="filterData.good" placeholder="商品名称" clearable></el-input>
          </el-autocomplete>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">实际客户:</div>
          <el-autocomplete v-model="filterData.client" placeholder="实际客户" :fetch-suggestions="querySearchAsync"
            style="width: 100%;">
          </el-autocomplete>
        </el-col>


        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">收货信息:</div>
          <el-input v-model="filterData.buyerinfo" placeholder="收货人,收货电话,收货地址" clearable></el-input>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">合作商:</div>
          <el-select v-model="filterData.supid" style="width: 100%;" clearable placeholder="合作商名称">
            <el-option v-for="(item,index) in suppliers" :key="item.name" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 30px;">
          <div style="width: 80px;">客户单位:</div>
          <el-autocomplete v-model="filterData.clientname" placeholder="客户企业名称" clearable
            :fetch-suggestions="querySearchClientnameAsync" style="width: 100%;"></el-autocomplete>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">业务员:</div>
          <el-select v-model="filterData.saleman" placeholder="业务员" clearable filterable allow-create
            style="width: 100%;">
            <el-option v-for="(item,index) in salelist" :label="item.name" :key="item.id"
              :value="item.name"></el-option>
          </el-select>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">进项状态:</div>
          <el-select v-model="filterData.supticket_status" placeholder="签收状态" style="width: 100%;" clearable>
            <el-option label="待签收" value="0"></el-option>
            <el-option label="已签收" value="1"></el-option>
          </el-select>
        </el-col>


        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">进项票号:</div>
          <el-input placeholder="进项发票号或数电票号" v-model="filterData.supticketid" clearable></el-input>
        </el-col>



        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">销项状态:</div>
          <el-select v-model="filterData.saleticket_status" placeholder="销项状态" style="width: 100%;" clearable>
            <el-option label="待开具" value="0"></el-option>
            <el-option label="已开具" value="1"></el-option>
          </el-select>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">销项发票:</div>
          <el-input placeholder="销项发票号或数电票号" v-model="filterData.saleticket_num" clearable></el-input>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">客票状态:</div>
          <el-select v-model="filterData.clientticket_status" placeholder="客户发票状态" style="width: 100%;" clearable>
            <el-option label="待上传" value="0"></el-option>
            <el-option label="已上传" value="1"></el-option>
          </el-select>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">客户票号:</div>
          <el-input placeholder="客户发票号" v-model="filterData.clientticket_fphm" clearable></el-input>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">提成状态:</div>
          <el-select v-model="filterData.commission_status" placeholder="业务提成状态" clearable style="width: 100%;">
            <el-option label="未结算" value="0"></el-option>
            <el-option label="已结算" value="1"></el-option>
          </el-select>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">认款状态:</div>
          <el-select v-model="filterData.requestpay_status" placeholder="认款状态" style="width: 100%;" clearable>
            <el-option label="未认款" value="0"></el-option>
            <el-option label="已认款" value="1"></el-option>
          </el-select>
        </el-col>


        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">收款状态:</div>
          <el-select v-model="filterData.income_status" placeholder="收款状态" style="width: 100%;" clearable>
            <el-option label="待收款" value="1"></el-option>
            <el-option label="已收款" value="2"></el-option>
          </el-select>
        </el-col>



        <el-col style="width: 280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">所属账套:</div>
          <el-select v-model="filterData.account" filterable placeholder="账套" style="width: 100%;" clearable>
            <el-option :label="item.name" :value="item.name" v-for="(item,index) in accounts" :key="index"></el-option>
          </el-select>
        </el-col>

        <el-col style="width:280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">订单状态:</div>
          <el-select v-model="filterData.status" placeholder="订单状态" style="width: 100%;" clearable>
            <el-option label="正常" value="0"></el-option>
            <el-option label="已取消" value="1"></el-option>
          </el-select>
        </el-col>


        <el-col style="width: 280px;display: flex;line-height: 35px;">
          <div style="width: 80px;">订单备注:</div>
          <el-input placeholder="订单备注" v-model="filterData.ordermemo" clearable></el-input>
        </el-col>


        <el-col style="width: 280px; line-height: 35px;">
          <el-form-item label="" label-width="25px">
            <el-checkbox v-model="filterData.containcancel">包含已取消订单</el-checkbox>
          </el-form-item>
        </el-col>
        <el-col style="width:120px">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" @click="handleQuery" style="width: 100%;"> 查询
            </el-button>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
    <div style="display: flex;">
      <div style="margin:5px 0px 2px; flex: 1;">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleNewOrder">新增销售订单</el-button>
      </div>
      <div style="text-align: right;margin:5px 0px 5px; display: flex;justify-content: flex-end;">
        <el-button type="primary" size="mini" icon="el-icon-download" :disabled="tableData.length<=0"
          @click="handleExport()">{{selection.length>0? '导出选中订单':'导出全部'}}</el-button>
        <el-popover width="240" trigger="click">
          <el-checkbox-group v-model="columnSelected">
            <el-row :gutter="10">
              <el-col v-for="item in columnHeaders" :key="item.title" :span="12">
                <el-checkbox :label="item.title"></el-checkbox>
              </el-col>
            </el-row>
          </el-checkbox-group>
          <el-button slot="reference" icon="el-icon-menu" size="mini" type="primary"
            style="margin-left: 2px;"></el-button>
        </el-popover>
      </div>
    </div>
    <!--订单列表 -->
    <div class="table-wraper">
      <el-table :data="tableData" ref="tableData" border height="100%" :header-row-style="{height:'30px'}"
        :header-cell-style="{'background-color': '#f5f7f9','color':'#363636',border:'1px solid #e8e8e8'}"
        :row-style="rowStyle" @selection-change="handleSelection" @select-all="handleSelection" @row-click="rowclicked">
        <el-table-column prop="ouid" label="id" v-if="false"></el-table-column>
        <el-table-column type="index" label="序号" width="50" align="center" fixed="left"></el-table-column>
        <el-table-column type="selection" width="45" align="center" fixed="left"></el-table-column>
        <el-table-column type="expand" label="详情">
          <template v-slot="scope">
            <div style="margin-left: 95px; width: 1000px;">
              <el-table :data="scope.row.goods" border>
                <el-table-column type="index" label="序号" align="center"></el-table-column>
                <el-table-column prop="sn" label="商品编码" align="center" width="150px"
                  show-overflow-tooltip></el-table-column>
                <el-table-column prop="platform" label="下单渠道" align="center" width="150px"
                  v-if="false"></el-table-column>
                <el-table-column prop="title" label="商品名称" width="200px" align="left"></el-table-column>
                <el-table-column prop="model" label="规格型号" align="left" width="100px"
                  show-overflow-tooltip></el-table-column>
                <el-table-column prop="unit" label="单位" width="50px" align="center"
                  show-overflow-tooltip></el-table-column>
                <el-table-column prop="count" label="数量" width="60px" align="center"></el-table-column>
                <el-table-column prop="price" label="单价" align="center" width="120px">
                  <template v-slot="scope">
                    {{format2Number(scope.row.price,2)}}
                  </template>
                </el-table-column>
                <el-table-column prop="total" label="总价" align="center" width="120px">
                  <template v-slot="scope">
                    {{format2Number(scope.row.total,2)}}
                  </template>
                </el-table-column>
                <el-table-column label="备注" prop="dmemo"></el-table-column>
              </el-table>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="status" v-if="columnHeaders[0].show" label="订单状态" align="center" width="80">
          <template v-slot="scope">
            <div style="cursor: pointer;" @click="handleStatusEdit(scope.$index,scope.row)">
              <span v-if="scope.row.status==0" style="color:#55aa00">正常</span>
              <span v-if="scope.row.status==1" style="color: #8f8f8f">已取消</span>
              <i class="el-icon-info" style="color: #ff5500;" v-if="scope.row.statusmemo!=''"
                :title="'备注:'+scope.row.statusmemo"></i>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="orderdate" v-if="columnHeaders[1].show" label="下单时间" width="140">
          <template v-slot="scope">
            <span v-if="scope.row.status==1" style="color: #8f8f8f"><del>{{scope.row.orderdate}}</del></span>
            <span v-if="scope.row.status!=1">{{scope.row.orderdate}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="内部单号" prop="ouid" width="110px" v-if="columnHeaders[2].show"
          show-overflow-tooltip>
          <template v-slot="scope">
            <span v-if="scope.row.status==1" style="color: #8f8f8f"><del>{{scope.row.ouid}}</del></span>
            <span v-if="scope.row.status!=1">{{scope.row.ouid}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="ordercode" v-if="columnHeaders[3].show" label="外部单号" align="center" width="150"
          show-overflow-tooltip>
          <template v-slot="scope">
            <span v-if="scope.row.status==1" style="color: #8f8f8f"><del>{{scope.row.ordercode}}</del></span>
            <span v-if="scope.row.status!=1">{{scope.row.ordercode}}</span>
          </template>
        </el-table-column>

        <el-table-column prop="platformtype" label="订单类型" width="80" align="center" v-if="columnHeaders[4].show">
          <template v-slot="scope">
            <span v-if="scope.row.status==1" style="color: #8f8f8f"><del>{{scope.row.platformtype}}</del></span>
            <span v-if="scope.row.status!=1">{{scope.row.platformtype}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="platform" v-if="columnHeaders[5].show" label="订单渠道" align="center" width="140"
          show-overflow-tooltip>
          <template v-slot="scope">
            <span v-if="scope.row.status==1" style="color: #8f8f8f"><del>{{scope.row.platform}}</del></span>
            <span v-if="scope.row.status!=1">{{scope.row.platform}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="amount" v-if="columnHeaders[6].show" label="订单总额" align="center" width="95">
          <template v-slot="scope">
            <span v-if="scope.row.status==1"
              style="color: #8f8f8f"><del>{{format2Number(scope.row.sum_order,4)}}</del></span>
            <span v-if="scope.row.status!=1">{{format2Number(scope.row.sum_order,4)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="ptamount" v-if="columnHeaders[7].show" label="应收总额" align="center" width="95">
          <template v-slot="scope">
            <span v-if="scope.row.status==1"
              style="color: #8f8f8f"><del>{{format2Number(scope.row.sum_platform,4)}}</del></span>
            <span v-if="scope.row.status!=1">{{format2Number(scope.row.sum_platform,4)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="supamount" v-if="columnHeaders[8].show" label="应付总额" align="center" width="95">
          <template v-slot="scope">
            <span v-if="scope.row.status==1"
              style="color: #8f8f8f"><del>{{format2Number(scope.row.sum_sup,4)}}</del></span>
            <span v-if="scope.row.status!=1">{{format2Number(scope.row.sum_sup,4)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="ordermemo" label="订单备注" v-if="columnHeaders[9].show"
          show-overflow-tooltip></el-table-column>

        <el-table-column label="收付款情况" align="center" v-if="columnHeaders[17].show">
          <el-table-column label="认款状态" align="center">
            <template v-slot="scope">
              <div style="cursor: pointer;" @click="handleRequestPay(scope.$index,scope.row)">
                <span v-if="scope.row.requestpay_status==0" style="color: #F56C6C;">未认款</span>
                <span v-if="scope.row.requestpay_status==1" style="color: #55aa00;">已认款</span>
                <i class="el-icon-info" style="color:#ff0000" v-if="scope.row.requestpay_memo!=''" :title="'认款备注:'+scope.row.requestpay_memo"></i>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="收款状态" align="center">
            <template v-slot="scope">
              <div style="cursor: pointer;" @click="handleInAmount(scope.$index,scope.row)">
                <span v-if="scope.row.income_rmb==0" style="color: #F56C6C;">未收款</span>
                <el-popover v-if="scope.row.income_rmb>0 && scope.row.income_rmb<scope.row.sum_platform" trigger="hover"
                  effect="light" placement="top">
                  <span>已收:{{scope.row.income_rmb}}</span>
                  <span slot="reference" style="color:#E6A23C">部分收款</span>
                </el-popover>
                <el-popover v-if="scope.row.income_rmb>0 && scope.row.income_rmb>=scope.row.sum_platform"
                  trigger="hover" effect="light" placement="top">
                  <span>已收:{{scope.row.income_rmb}}</span>
                  <span slot="reference" style="color: #67C23A;">已收款</span>
                </el-popover>
              </div>
            </template>
          </el-table-column>
        </el-table-column>


        <el-table-column label="收货信息" v-if="columnHeaders[10].show" align="center">
          <el-table-column label="收货地址"  show-overflow-tooltip>
            <template slot="header">
              <div style="text-align: center;">收货地址</div>
            </template>
            <template v-slot="scope">
              <span v-if="scope.row.status==1" style="color: #8f8f8f"><del>
                <i class="el-icon-document-copy" @click="copyText(scope.row.buyerinfo.buyer+' '+scope.row.buyerinfo.mobile+' '+scope.row.buyerinfo.address)"></i>

                  {{scope.row.buyerinfo.buyer}}
                  {{scope.row.buyerinfo.mobile}} {{scope.row.buyerinfo.address}}</del>
              </span>
              <span v-if="scope.row.status!=1">
                <i class="el-icon-document-copy" @click="copyText(scope.row.buyerinfo.buyer+' '+scope.row.buyerinfo.mobile+' '+scope.row.buyerinfo.address)"></i>
              {{scope.row.buyerinfo.buyer}}
              {{scope.row.buyerinfo.mobile}}
              {{scope.row.buyerinfo.address}}</span>
            </template>
          </el-table-column>
          <el-table-column label="客户单位名称" prop="clientname" show-overflow-tooltip width="150px"></el-table-column>
        </el-table-column>
        <el-table-column label="实际客户" prop="client" align="center" show-overflow-tooltip v-if="columnHeaders[11].show"
          width="100px"></el-table-column>
        <el-table-column prop="saleman" label="业务员" width="80px" v-if="columnHeaders[12].show"
          align="center"></el-table-column>

        <el-table-column label="采购成本" align="center" v-if="columnHeaders[13].show">
          <template slot="header">
            <div style="text-align: center;">采购成本</div>
          </template>
          <el-table-column label="成本状态" prop="bind_buydetail_status" align="center" width="80px">
            <template v-slot="scope" >
              <div style="cursor: pointer;" @click="handleShowBind(scope.$index,scope.row)">
                <span v-if="scope.row.bind_buydetail_status==0">不完整</span>
                <span v-if="scope.row.bind_buydetail_status==1">完整</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="成本总额" prop="bind_buydetail_sum" align="center" width="95px">
            <template v-slot="scope">
              {{scope.row.bind_buydetail_sum}}
            </template>
          </el-table-column>
          <el-table-column label="采购单号" prop="bind_buydetail_buycode" align="center" width="100px" show-overflow-tooltip>
            <template v-slot="scope">
              <span>{{scope.row.bind_buydetail_buycode}}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="进项发票" align="center" v-if="columnHeaders[14].show">
          <el-table-column prop="supticket_status" label="签收状态" width="90" align="center">
            <template v-slot="scope">
              <div style="cursor: pointer;" @click="handleSupTicket(scope.$index,scope.row)">
                <span v-if="scope.row.supticket_status==0" style="color:#FF0000">待签收</span>
                <span v-if="scope.row.supticket_status==1" style="color: #67C23A;">已签收</span>
                <i class="el-icon-info" style="color: #ff0000;" v-if="scope.row.supticket_statusmemo!=''"
                  :title="scope.row.supticket_statusmemo"></i>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="进项票号" prop="supticket_ids" show-overflow-tooltip>
            <template v-slot="scope">
              {{scope.row.supticket_ids.join(",")}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="销售发票" align="center" v-if="columnHeaders[15].show">
          <el-table-column label="开具状态" align="center">
            <template v-slot="scope">
              <div style="cursor: pointer;" @click="handleSaleTicket(scope.$index,scope.row)">
                <span v-if="scope.row.platformticket_status==0" style="color: #FF0000;">待开具</span>
                <span v-if="scope.row.platformticket_status==1" style="color:#55aa00">已开具</span>
                <i class="el-icon-info" style="color: #ff0000;" v-if="scope.row.platformticket_statusmemo!=''"
                  :title="scope.row.platformticket_statusmemo"></i>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="销项票号" align="center" prop="platformticket_ids" show-overflow-tooltip>
            <template v-slot="scope">
              {{scope.row.platformticket_ids.join(",")}}
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="客户发票" align="center" v-if="columnHeaders[16].show">
          <el-table-column label="签收单模板" align="center" width="90px">
            <template v-slot="scope">
              <div style="cursor: pointer;" @click="handleDeliverSignTemplate(scope.$index,scope.row)">
                <span v-if="scope.row.deliver_sign_template==''" style="color: #FF0000;">待上传</span>
                <span v-if="scope.row.deliver_sign_template!=''" style="color: #55aa00;">已上传</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="客户发票" align="center">
            <template v-slot="scope">
              <div style="cursor: pointer;" @click="handleClientTicket(scope.$index,scope.row)">
                <span v-if="scope.row.clientticket_attach==''" style="color: #FF0000;">待上传</span>
                <span v-if="scope.row.clientticket_attach!=''" style="color: #55aa00;">已上传</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="客户发票号" align="center" prop="clientticket_fphm" show-overflow-tooltip
            width="90px"></el-table-column>
          <el-table-column label="合作商结算" align="center" width="100px" show-overflow-tooltip>
            <template v-slot="scope">
              <div style="cursor: pointer;" @click="handleInAmount(scope.$index,scope.row)">
                <span v-if="scope.row.paid_status==0" style="color:#F56C6C">待支付</span>
                <span v-if="scope.row.paid_status==1" style="color:#67C23A" :title="'已付:'+scope.row.paid_rmb">已支付</span>
              </div>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="业务提成" align="center" v-if="false">
          <el-table-column prop="saleman" label="业务员" width="80px" align="center"></el-table-column>
          <el-table-column prop="commission_rmb" label="金额" width="95px" align="center">
            <template v-slot="scope">
              {{scope.row.commission_rmb}} <span v-if="scope.row.commission_memo!=''" style="margin-left:2px;"
                :title="'备注:'+scope.row.commission_memo"><i class="el-icon-info"
                  style="color: #ff5500; cursor: pointer;"></i></span>
            </template>
          </el-table-column>
          <el-table-column prop="commission_status" label="状态" width="80px" align="center">
            <template v-slot="scope">
              <span v-if="scope.row.commission_status==0" style="color: #F56C6C;">未付款</span>
              <span v-if="scope.row.commission_status==1" style="color: #67C23A;">已付款</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column prop="supname" label="合作商" show-overflow-tooltip width="120px" v-if="columnHeaders[18].show"
          align="center">
        </el-table-column>
        <el-table-column prop="account" label="所属账套" show-overflow-tooltip width="120px" v-if="columnHeaders[19].show"
          align="center"></el-table-column>

        <el-table-column label="操作" fixed="right" width="140" align="center" border>
          <template v-slot="scope">
            <el-button-group>
              <el-button type="infor" size="mini" circle icon="el-icon-edit-outline"
                @click="handleEdit(scope.$index,scope.row)" title="修改订单"></el-button>
              <el-button size="mini" circle type="success" icon="el-icon-money" title="销售提成管理"
                @click="handleCommissionShow(scope.$index,scope.row)"></el-button>
              <el-button size="mini" v-if="scope.row.attach.length>0" circle type="infor" icon="el-icon-download"
                title="下载合同" @click="handleDownload(scope.$index,scope.row.attach)"></el-button>
              <el-button size="mini" circle type="danger" icon="el-icon-delete" title="删除订单"
                @click="handleDeleteOrder(scope.$index,scope.row)"></el-button>
              <el-button size="mini" v-if="false" circle type="danger" icon="el-icon-delete" title="取消订单"
                @click="handleCancelOrder(scope.$index, scope.row);"></el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <EditUI ref="editUI" v-if="editVisible" @update="handleEditCompleteHandler"></EditUI>
    <GetAmountUI ref="getamountUI" v-if="inamountVisible" @getamountChangedHandler="handleGetAmountCompleteHandler"
      @paidamountChangeHandler="handlePaidAmountComplateHandler" @paidstatusChangeHandler="paidStatusChangedHandler">
    </GetAmountUI>
    <DeliverUI ref="deliverUI" v-if="deliverVisible" />
    <SupticketUI ref="platformTicketUI" v-if="supticketVisible" @closeHandler="handletsupticket_verify"></SupticketUI>
    <PrinterUI v-if="printVisible" ref="printerUI"></PrinterUI>
    <DispatchUI ref="dispatchUI" v-if="dispatchVisible" @closeHandler="handleStatusEditCallback"></DispatchUI>

    <CancelOrderUI ref="cancelOrderUI" v-if="cancelVisible"></CancelOrderUI>

    <CreateUI ref="createUI" v-if="createVisible" @updated="curpage=1;loadDataList();"></CreateUI>
    <CommissionUI ref="commissionUI" v-if="commisionVisible" @updated="handleCommisionUpdateCallback"></CommissionUI>

    <DeliverSignDocUploadUI v-if="deliverSignUploadVisible" ref="deliverSignUploadUI"
      @closeHandler="handleSignTempalteUpdate"></DeliverSignDocUploadUI>

    <ClientTicketUI v-if="clientTicketVisible" ref="clientTicketUI" @closeHandler="handleClientTicketCallback">
    </ClientTicketUI>
    <SaleticketBindUI v-if="saleticketbindVisible" ref="saleticketBindUI"></SaleticketBindUI>
    <StatusUI v-if="statusVisible" ref="statusUI" @updated="handleStatusUpdated"></StatusUI>
    <BuyTicketFilterUI v-if="buyticketFilterVisible" ref="buyTicketFilterUI"></BuyTicketFilterUI>
    <RequestPayUI v-if="requestPayVisible" ref="requestPayUI" @closeHandler="handleRequestPayCallback"></RequestPayUI>

    <div style="display: flex;">
      <div style="flex: 1; line-height: 45px;">
        <span style="margin-right: 30px;">订单总额:{{sum_order}}</span>
        <span style="margin-right: 30px;">应收总额:{{sum_platform}} </span>
        <span style="margin-right: 30px;">应付总额:{{sum_sup}} </span>
        <span style="margin-right:30px">提成总额:{{rmb4saletotal}}</span>
        <span style="margin-right:30px">选中总额:{{parseFloat(sumamount_selection).toFixed(4)}}</span>
        <span style="margin-right:30px">选中应付总额:{{parseFloat(sumsup_selection).toFixed(4)}}</span>
        <span style="margin-right:30px">选中总成本:{{parseFloat(sumcost_selection).toFixed(4)}}</span>
      </div>
      <div style="margin-top: 10px; text-align: right;">
        <el-pagination class="pagination" prev-text="上一页" next-text="下一页" background
          layout=" prev, pager, next,sizes,total" :page-sizes="[15, 60, 120,200]" :total="numrows" :page-size="pagesize"
          :current-page="curpage" @size-change="handleSizeChange" @current-change="handleCurrentChange">
        </el-pagination>
      </div>
    </div>
    <el-row :gutter="30">
      <el-col :span="4">
        <div class="title">订单收付款</div>
        <div v-if="selectRow!=null">
          <el-row>
            <el-col>
              <div style="display: flex; line-height: 25px;">
                <div style="font-weight: bold;">订单总额:</div>
                <div style="padding-left: 10px;"> ¥{{parseFloat(selectRow.sum_order).toFixed(2)}}</div>
              </div>
            </el-col>
            <el-col>
              <div style="display: flex; line-height: 25px;">
                <div style="font-weight: bold;">应收总额: </div>
                <div style="padding-left: 10px;">
                  ¥{{parseFloat(selectRow.sum_platform).toFixed(2)}}
                </div>
              </div>
            </el-col>
          </el-row>

          <div style="display: flex; line-height: 25px;">
            <div style="font-weight: bold;">认款状态: </div>
            <div style="padding-left: 10px;">
              <span v-if="selectRow.requestpay_status==0" style="color: #F56C6C;">未认款</span>
              <span v-if="selectRow.requestpay_status==1" style="color: #55aa00;">已认款</span>
            </div>
          </div>
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">收款状态: </div>
            <div style="cursor: pointer;padding-left: 10px;" @click="handleInAmount(rowIndex,selectRow)">
              <span v-if="selectRow.income_rmb==0" style="color: #F56C6C;">未收款</span>
              <el-popover v-if="selectRow.income_rmb>0 && selectRow.income_rmb<selectRow.sum_platform" trigger="hover"
                effect="light" placement="top">
                <span>已收:{{selectRow.income_rmb}}</span>
                <span slot="reference" style="color:#E6A23C">部分收款</span>
              </el-popover>
              <el-popover v-if="selectRow.income_rmb>0 && selectRow.income_rmb>=selectRow.sum_platform" trigger="hover"
                effect="light" placement="top">
                <span>已收:{{selectRow.income_rmb}}</span>
                <span slot="reference" style="color: #67C23A;">已收款</span>
              </el-popover>
            </div>
          </div>
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">合作商结算状态: </div>
            <div style="cursor: pointer;padding-left: 10px;" @click="handleInAmount(rowIndex,selectRow)">
              <span v-if="selectRow.paid_status==0" style="color:#F56C6C">待支付</span>
              <span v-if="selectRow.paid_status==1" style="color:#67C23A" :title="'已付:'+selectRow.paid_rmb">已支付</span>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="title">进项发票</div>
        <div v-if="selectRow!=null">
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">签收状态: </div>
            <div style="cursor: pointer;padding-left: 10px;" @click="handleSupTicket(rowIndex,selectRow)">
              <span v-if="selectRow.supticket_status==0" style="color: #F56C6C;">待开具</span>
              <span v-if="selectRow.supticket_status==1" style="color: #67C23A;">已签收</span>
            </div>
          </div>
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">进项票号: </div>
            <div style="overflow: auto; padding-left: 10px;">
              <div v-for="id in selectRow.supticket_ids">
                {{id}}
              </div>
            </div>
          </div>
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">签收备注: </div>
            <div style="overflow: auto; padding-left: 10px;">
              {{selectRow.supticket_statusmemo}}
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="title">销项发票</div>
        <div v-if="selectRow!=null">
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">开票状态: </div>
            <div style="cursor: pointer;padding-left: 10px;" @click="handleSaleTicket(rowIndex,selectRow)">
              <span v-if="selectRow.platformticket_status==0" style="color: #F56C6C;">待开具</span>
              <span v-if="selectRow.platformticket_status==1" style="color: #67C23A;">已开具</span>
            </div>
          </div>
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">销项票号: </div>
            <div style="overflow: auto; padding-left: 10px;">
              <div v-for="id in selectRow.platformticket_ids">
                {{id}}
              </div>
            </div>
          </div>
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">签收备注: </div>
            <div style="overflow: auto; padding-left: 10px;">
              {{selectRow.platformticket_statusmemo}}
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="title">客户相关文件及发票</div>
        <div v-if="selectRow!=null">
          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">签收单模板: </div>
            <div style="cursor: pointer;padding-left: 10px;" v-if="selectRow.deliver_sign_template!=''"
              @click="handleDeliverSignTemplate(rowIndex,selectRow)">
              <span class="el-icon-view" style="margin-right: 10px;">预览</span>
            </div>
            <div style="cursor: pointer;padding-left: 10px;" v-if="selectRow.deliver_sign_template==''"
              @click="handleDeliverSignTemplate(rowIndex,selectRow)">
              <span style="margin-right: 10px;color:#F56C6C">未上传</span>
            </div>
          </div>

          <div style="display: flex;line-height: 25px;">
            <div style="font-weight: bold;">客户发票: </div>
            <div style="cursor: pointer;padding-left: 10px;" v-if="selectRow.clientticket_attach!=''"
              @click="handleClientTicket(rowIndex,selectRow)">
              <span class="el-icon-view" style="margin-right: 10px;">预览</span>
            </div>
            <div style="cursor: pointer;padding-left: 10px;" v-if="selectRow.clientticket_attach==''"
              @click="handleClientTicket(rowIndex,selectRow)">
              <span style="margin-right: 10px;color:#F56C6C">未上传</span>
            </div>

            </div>
            <div style="display: flex;line-height: 25px;">
              <div style="font-weight: bold;">客户发票号: </div>
              <div style="overflow: auto; padding-left: 10px;">
                {{selectRow.clientticket_fphm}}
              </div>
          </div>

        </div>
      </el-col>
    </el-row>
    <div></div>
  </div>
</template>

<script>
  import EditUI from './edit.vue';
  import GetAmountUI from './GetAmountUI.vue'
  import DeliverUI from './DeliverUI.vue'
  import SupticketUI from './SupticketUI.vue'
  import PlatformTicketIn from './PlatformTicketIn.vue';
  import DispatchUI from './DispathUI.vue'
  import PrinterUI from './Printer.vue'
  import CancelOrderUI from './CancelOrder.vue';
  import qs from 'qs';
  import CommissionUI from './commission.vue';
  import CreateUI from './create.vue';
  import DeliverSignDocUploadUI from './DeliverSignDocUpload.vue';
  import ClientTicketUI from './ClientTicket.vue';
  import SaleticketBindUI from './saleticketbind.vue';
  import StatusUI from './statusUI.vue';
  import BuyTicketFilterUI from './buyticketfilter.vue'
  import RequestPayUI from './RequstPayUI.vue'

  export default {
    components: {
      RequestPayUI,
      CreateUI,
      EditUI,
      GetAmountUI,
      DeliverUI,
      SupticketUI,
      PlatformTicketIn,
      DispatchUI,
      PrinterUI,
      CommissionUI,
      CancelOrderUI,
      DeliverSignDocUploadUI,
      ClientTicketUI,
      SaleticketBindUI,
      StatusUI,
      BuyTicketFilterUI
    },
    mounted() {
      var now= new Date();
      var firstDay=this.formatDate(new Date(now.getFullYear(),now.getMonth(),1));
      var lastDay=this.formatDate(new Date(now.getFullYear(),now.getMonth()+1,0));
      this.filterData.daterange = [firstDay,lastDay];


      if (localStorage.getItem(this.$route.name) == null) {
        localStorage.setItem(this.$route.name, JSON.stringify(this.columnSelected));
      } else {
        this.columnSelected = JSON.parse(localStorage.getItem(this.$route.name));
      }

      if(this.$route.query&& this.$route.query.saleticket_status!=''){
        this.filterData.saleticket_status=this.$route.query.saleticket_status;
      }

      if(this.$route.query&& this.$route.query.income_status!=''){
        this.filterData.income_status=this.$route.query.income_status;
      }


      this.loadAccounts();
      this.loadDataList();
      this.loadPlatforms();
      this.loadSuppliers();
      this.loadSalemans();
    },
    watch: {
      columnSelected(newArrayVal) {
        this.columnHeaders.filter(item => {
          if (newArrayVal.indexOf(item.title) != -1) {
            item.show = true;
          } else {
            item.show = false;
          }
        })
        this.$nextTick(() => {
          this.$refs.tableData.doLayout()
        })

        localStorage.setItem(this.$route.name, JSON.stringify(newArrayVal));
      }
    },
    data() {
      return {

        selectedArrData: [],
        columnSelected: ["状态", "下单时间", "内部单号", "外部单号", "订单类型", "下单渠道", "订单总额", "应收总额", "应付总额", "订单备注", "收货人信息", "客户联系人",
          "业务员", "采购成本", "进项发票", "销项发票", "客户发票", "收付款情况", "合作商", "所属账套"
        ],
        columnHeaders: [{
            "title": "状态",
            "show": true
          },
          {
            "title": "下单时间",
            "show": true
          },
          {
            "title": "内部单号",
            "show": true
          },
          {
            "title": "外部单号",
            "show": true
          },
          {
            "title": "订单类型",
            "show": true
          },
          {
            "title": "下单渠道",
            "show": true
          },
          {
            "title": "订单总额",
            "show": true
          },
          {
            "title": "应收总额",
            "show": true
          },
          {
            "title": "应付总额",
            "show": true
          },
          {
            "title": "订单备注",
            "show": true
          },
          {
            "title": "收货人信息",
            "show": true
          },
          {
            "title": "客户联系人",
            "show": true
          },
          {
            "title": "业务员",
            "show": true
          },

          {
            "title": "采购成本",
            "show": true
          },
          {
            "title": "进项发票",
            "show": true
          },
          {
            "title": "销项发票",
            "show": true
          },
          {
            "title": "客户发票",
            "show": true
          },
          {
            "title": "收付款情况",
            "show": true
          },
          {
            "title": "合作商",
            "show": true
          },
          {
            "title": "所属账套",
            "show": true
          },
        ],
        rowIndex: -1,
        rowName: '',
        accounts: [],
        salelist: [],
        suppliers: [],
        JsonFields: {
          "ouid": 'ouid',
          "下单时间": {
            field: 'orderdate',
            callback: (value) => {
              return "'" + value;
            }
          },
          "区域": "region_values",
          "子订单号": {
            field: 'ordercode',
            callback: (value) => {
              return "'" + value;
            }
          },
          "下单渠道": "platform",
          "订单总额": "amount",
          "应付总额": "ptamount",
          "京东编码": {
            field: 'good.sn',
            callback: (value) => {
              return "'" + value;
            }
          },
          "商品名称": "good.title",
          "单位": "good.unit",
          "数量": "good.count",
          "商城单价": "good.price",
          "订单小计": "good.total",
          "渠道单价": "good.ptprice",
          "渠道小计": "good.pttotal",
          "供应商单价": "good.supprice",
          "供应商总额": "good.suptotal",
          "订单备注": "ordermemo",
          "业务员": "saleman",
          "供应商": "supname",
          "客户名称": "clientuser",
          "收货人": "buyerinfo.buyer",
          "收货电话": "buyerinfo.mobile",
          "收货地址": "buyerinfo.address",
          "合作商发票": {
            field: 'supticket_status',
            callback: (value) => {
              return value == "0" ? "待开" : "已审核";
            }
          },
          "供应商进项票号": "supticket_ids",
          "平台发票销项": {
            field: 'platformticket_status',
            callback: (value) => {
              return value == "1" ? "已开票" : "未开票"
            }
          },
          "平台发票票号": "platformticket_ids",
          "收款状态": {
            field: 'income_status',
            callback: (value) => {
              return value == "1" ? "未收款" : (value == 3 ? "已收款" : "部分收款");
            }
          },
          "付款状态": {
            field: 'paidstatus',
            callback: (value) => {
              return value == "0" ? "未付款" : "已付款";
            }
          }
        },
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        filterData: {
          ouid: '',
          daterange: '',
          type: '',
          mordercode: '',
          ordercode: '',
          supid: '',
          subordercode: '',
          sticket_status: '',
          buyerinfo: '',
          platform: '',
          good: '',
          ordermemo: '',
          income_status: '',
          paid_tatus: '',
          supticket_status: '',
          saleticket_status: '',
          clientticket_fphm: '',
          clientticket_status: '',
          supticketid: '',
          commission_status: '',
          requestpay_status:'',
          saleman: '',
          client: '',
          account: '',
          clientname: '',
          containcancel: true,
          cost_bindstatus: '',
          status:''
        },
        platforms: [],
        //表格与分页相关
        tableData: [],
        curpage: 1,
        pagesize: 15,
        numrows: 1,
        sum_order: 0, //订单总额
        sum_platform: 0,
        sum_sup: 0,
        rmb4saletotal: 0,
        createVisible: false,
        editVisible: false,
        inamountVisible: false,
        deliverVisible: false,
        supticketVisible: false,
        platformticketinVisible: false,
        dispatchVisible: false,
        printVisible: false,
        commisionVisible: false,
        cancelVisible: false,
        buyticketFilterVisible: false,
        selection: [],
        sumamount_selection: 0,
        sumsup_selection: 0,
        sumcost_selection: 0,
        deliverSignUploadVisible: false,
        clientTicketVisible: false,
        saleticketbindVisible: false,
        requestPayVisible: false,
        statusVisible: false,
        selectRow: null
      }
    },
    methods: {
      formatDate(date) {
        const yyyy = date.getFullYear();
        const mm = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的
        const dd = String(date.getDate()).padStart(2, '0');
        return `${yyyy}-${mm}-${dd}`;
      },
      copyText(txt){
          if(txt==""){
            return;
          }
            const el = document.createElement('textarea');
              // 将需要复制的文本内容赋值给 textarea 元素。
              el.value = txt;
              //将 textarea 元素添加到页面中。
              document.body.appendChild(el);
              //选中 textarea 元素中的文本。
              el.select();
              // 执行复制命令，将选中的文本复制到剪贴板
              document.execCommand('copy');
              //从页面中移除 textarea 元素。
              document.body.removeChild(el);
              //弹出提示框，告知用户文本已复制成功。
              this.$message.success("文本已复制");
      },
      getCurrentDate(n) {
            var dd = new Date();
            if (n) {
              dd.setDate(dd.getDate() - n);
            }
            var year = dd.getFullYear();
            var month =
              dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
            var day = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
            return year + "-" + month + "-" + day;
          },
      handleRequestPay(index,data){
        this.requestPayVisible=true;
        this.$nextTick(()=>{
          this.$refs.requestPayUI.dialogVisible=true;
          this.$refs.requestPayUI.init(index,JSON.parse(JSON.stringify(data)));
        })
      },
      handleRequestPayCallback(index,data){
        this.tableData[index].requestpay_memo=data.requestpay_memo;
        this.tableData[index].requestpay_status=data.requestpay_status;
      },
      handleClientTicketCallback(index, data) {
        this.tableData[index].clientticket_attach = data.clientticket_attach;
        this.tableData[index].clientticket_fphm = data.clientticket_fphm;
      },
      rowStyle({
        row
      }) {
        if (this.selectRow && this.selectRow.ouid == row.ouid) {
          return {
            backgroundColor: '#dcdcdc',
            color: '#000000',
            cursor: 'pointer',
          };
        }
        return {
          'cursor': 'pointer'
        };
      },
      rowclicked(row, event, column) {
        this.selectedArrData = [row];
        this.rowName = row.name;
        this.rowIndex = -1;
        var that = this;
        var option = this.tableData.filter(function(cur, index, a) {
          if (cur.ouid == row.ouid) {
            that.rowIndex = index;
            return cur;
          }
        })[0];
        this.selectRow = option;
      },
      handleSaleTicket(index, data) {
        this.saleticketbindVisible = true;
        this.$nextTick(() => {
          this.$refs.saleticketBindUI.dialogVisible = true;
          this.$refs.saleticketBindUI.init(index, data);
        })
      },
      handleDeliverSignTemplate(index, data) {
        this.deliverSignUploadVisible = true;
        this.$nextTick(() => {
          this.$refs.deliverSignUploadUI.dialogVisible = true;
          this.$refs.deliverSignUploadUI.init(index, JSON.parse(JSON.stringify(data)));
        })
      },
      handleSignTempalteUpdate(index, data) {
        this.tableData[index].deliver_sign_template = data;
      },
      handleClientTicket(index, data) {
        this.clientTicketVisible = true;
        this.$nextTick(() => {
          this.$refs.clientTicketUI.dialogVisible = true;
          this.$refs.clientTicketUI.init(index, JSON.parse(JSON.stringify(data)));
        })
      },
      loadAccounts() {
        this.axios.post("api/admin/account/list").then(res => {
          if (res.status == 200 && res.data.code == 0) {
            this.accounts = res.data.list;
          }
        })
      },
      handleNewOrder() {
        this.createVisible = true;
        this.$nextTick(() => {
          this.$refs.createUI.dialogVisible = true;
          this.$refs.createUI.init();
        })
      },
      querySearchAsync(str, cb) {
        this.axios.post("api/admin/clientuser/filter", {
          username: str
        }).then(res => {
          if (res.data.code) {
            cb(res.data.data);
          }
        })
      },
      querySearchClientnameAsync(str, cb) {
        this.axios.post("api/admin/client/filter", {
          name: str
        }).then(res => {
          if (res.data.code) {
            cb(res.data.data);
          }
        })
      },
      loadSalemans() {
        this.axios.post("api/admin/mate/list_op").then(res => {
          if (res.status == 200 && res.data.code == 0) {
            this.salelist = res.data.list;
          }
        })
      },
      handleCommissionShow(index, data) {
        this.commisionVisible = true;
        this.$nextTick(() => {
          this.$refs.commissionUI.dialogVisible = true;
          this.$refs.commissionUI.init(index, JSON.parse(JSON.stringify(data)));
        })
      },
      handleCommisionUpdateCallback(index, data) {
        this.tableData[index].commission_rmb = parseFloat(data.commission_rmb).toFixed(2);
        this.tableData[index].commission_status = data.commission_status;
        this.tableData[index].commission_memo = data.commission_memo;
      },
      loadSuppliers: function() {
        this.axios.post("api/admin/supplier/list_item").then(res => {
          if (res.status == 200 && res.data.code == 0) {
            this.suppliers = res.data.list;
          }
        })
      },
      handleSelection(selection) {
        this.selection = selection;
        this.sumamount_selection = 0;
        this.sumsup_selection = 0;
        this.sumcost_selection = 0;
        this.selection.forEach((item) => {
          this.sumamount_selection += parseFloat(item.sum_order);
          this.sumsup_selection += parseFloat(item.sum_sup);
          this.sumcost_selection += parseFloat(item.sum_cost);
        })



      },
      loadPlatforms: function() {
        this.axios.post("/api/admin/platform/list").then(res => {
          if (res.status == 200 && res.data.code == 0) {
            this.platforms = res.data.platforms;
          }
        })
      },
      handleQuery: function() {
        this.curpage = 1;
        this.loadDataList();
      },
      handleSizeChange: function(val) {
        this.pagesize = val;
        this.curpage = 1;
        this.loadDataList();
      },
      handleCurrentChange: function(val) {
        this.curpage = parseInt(val);
        this.loadDataList();
      },
      loadDataList: function() {
        let params = {
          daterange: this.filterData.daterange,
          curpage: this.curpage,
          pagesize: this.pagesize,
          ouid: this.filterData.ouid,
          ordercode: this.filterData.ordercode,
          buyerinfo: this.filterData.buyerinfo,
          good: this.filterData.good,
          platform: this.filterData.platform == "全部" ? "" : this.filterData.platform,
          supid: this.filterData.supid,
          commission_status: this.filterData.commission_status,
          ordermemo: this.filterData.ordermemo,
          client: this.filterData.client,
          account: this.filterData.account,
          clientname: this.filterData.clientname,
          saleticket_status: this.filterData.saleticket_status,
          saleticket_num: this.filterData.saleticket_num,
          supticketid: this.filterData.supticketid,
          clientticket_status: this.filterData.clientticket_status,
          clientticket_fphm: this.filterData.clientticket_fphm,
          requestpaystatus:this.filterData.requestpay_status,
          income_status: this.filterData.income_status,
          paid_status: this.filterData.paid_tatus == "全部" ? "" : this.filterData.paid_tatus,
          supticket_status: this.filterData.supticket_status == "全部" ? "" : this.filterData.supticket_status,
          saleman: this.filterData.saleman,
          cost_bindstatus: this.filterData.cost_bindstatus,
          containcancel: this.filterData.containcancel ? 1 : 0,
          status:this.filterData.status
        }
        this.axios.post("/api/admin/order/list", params).then(res => {
          if (res.status == 200 && res.data.code == 0) {
            this.curpage = res.data.curpage;
            this.pagesize = res.data.pagesize;
            this.numrows = res.data.numrows;
            this.tableData = res.data.list;
            this.sum_order = res.data.sum_order;
            this.sum_platform = res.data.sum_platform;
            this.sum_sup = res.data.sum_sup;

            this.$refs.tableData.doLayout();

            this.getExpendIds();
          } else {
            this.$message.error("获取订单列个失败!");
          }
        });
      },
      getExpendIds() {
        var els = document.getElementsByClassName("el-table__expand-icon");
        for (let i = 0; i < els.length; i++) {
          els[i].click();
        }
      },
      format2Number(value, len) {
        var f = parseFloat(value);
        var f = Math.round(value * 10000) / 10000;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
          rs = s.length;
          s += '.';
        }
        while (s.length <= rs + len) {
          s += '0';
        }
        return s;
      },
      /********编辑订单信息************/
      handleEdit: function(index, row) {
        this.editVisible = true;
        this.$nextTick(() => {
          this.$refs.editUI.init(index, JSON.parse(JSON.stringify(row)))
          this.$refs.editUI.dialogVisible = true;
        })
      },
      handleEditCompleteHandler: function(index, form, sumorder, sumplatform, sumsup) {
        console.log(form, sumorder, sumplatform, sumsup);
        this.tableData[index].platformid = form.platformid;
        this.tableData[index].platform = form.platform;
        this.tableData[index].sum_order = form.sum_order;
        this.tableData[index].buyerinfo.buyer = form.buyerinfo.buyer;
        this.tableData[index].buyerinfo.mobile = form.buyerinfo.mobile;
        this.tableData[index].buyerinfo.address = form.buyerinfo.address;
        this.tableData[index].region_ids = form.region_ids;
        this.tableData[index].region_values = form.region_values;
        this.tableData[index].client = form.client;
        this.tableData[index].clientname = form.clientname;
        this.tableData[index].ordermemo = form.ordermemo;
        this.tableData[index].goods = form.goods;
        this.tableData[index].supid = form.supid;
        this.tableData[index].supname = form.supname;
        this.tableData[index].suprate = form.suprate;
        this.tableData[index].platformrate = form.platformrate;
        this.tableData[index].platformtype = form.platformtype;
        this.tableData[index].saleman = form.saleman;
        this.tableData[index].orderdate = form.orderdate;
        this.tableData[index].ordercode = form.ordercode;
        this.tableData[index].sum_order = this.format2Number(sumorder, 4);
        this.tableData[index].sum_sup = this.format2Number(sumsup, 4);
        this.tableData[index].sum_platform = this.format2Number(sumplatform, 4);
        this.tableData[index].attach = form.attach;
      },
      handleInAmount: function(index, row) {
        this.inamountVisible = true;
        this.$nextTick(() => {
          this.$refs.getamountUI.dialogVisible = true;
          this.$refs.getamountUI.init(index, JSON.parse(JSON.stringify(row)))
        })
      },
      handleGetAmountCompleteHandler: function(index, sum, status) {
        //console.log(index, sum);
        this.tableData[index].income_rmb = sum;
        this.tableData[index].income_status = status;
      },
      handlePaidAmountComplateHandler: function(index, sum, status) {
        this.tableData[index].paidamount = sum;
        this.tableData[index].paidstatus = status;
      },
      paidStatusChangedHandler: function(index, status) {
        this.tableData[index].paid_status = status;
      },
      //查看快递信息
      handleDeliver(index, row) {
        this.deliverVisible = true;
        this.$nextTick(() => {
          this.$refs.deliverUI.dialogVisible = true;
          this.$refs.deliverUI.init(index, JSON.parse(JSON.stringify(row)))
        })
      },
      //查看进项申请
      handleSupTicket(index, row) {
        this.supticketVisible = true;
        this.$nextTick(() => {
          this.$refs.platformTicketUI.init(index, JSON.parse(JSON.stringify(row)))
          this.$refs.platformTicketUI.dialogVisible = true;
        })
      },
      //*****************平台销项票*******************//
      handlePlatformTicket(index, row) {
        this.platformticketinVisible = true;
        this.$nextTick(() => {
          this.$refs.platformticketinUI.dialogVisible = true;
          this.$refs.platformticketinUI.init(index, JSON.parse(JSON.stringify(row)))
        })
      },
      handleupdate_paidstatus(index, status) {
        this.tableData[index].paidstatus = status;
      },
      handlePlatformTicketinStatus(index, status, ticketinids, attach) {
        this.tableData[index].saleticket_status = status;
        this.tableData[index].saleticket_nums = ticketinids.join(",");
      },
      handletsupticket_verify(index, detail) {
        this.tableData[index].supticket_status = detail.status;
        this.tableData[index].supticket_signedtime = detail.date;
        this.tableData[index].supticket_signedmemo = detail.memo;
        this.tableData[index].supticket_verifymsg = detail.msg;
        this.tableData[index].supticket_amount = detail.amount;
        this.tableData[index].supticket_same = detail.same;
        this.tableData[index].supticket_memo = detail.supticket_memo;
      },
      handleSupticketSigned(index, detail) {
        this.tableData[index].supticket_signedtime = detail.supticket_signedtime;
        this.tableData[index].supticket_signedmemo = detail.supticket_signedmemo;
        this.tableData[index].supticket_status = detail.supticket_status;
      },
      handleResetStatus(index) {
        this.tableData[index].supticket_status = 0;
        this.tableData[index].supticket_detail = [];
      },
      handleDeleteOrder(index, row) {
        var that = this;
        this.$confirm("确定要删除" + row.ordercode + "订单吗？", "操作确认", {
          confirmButtonText: "确定删除",
          cancelButtonText: "取消",
          type: 'error'
        }).then(() => {
          this.axios.post("api/admin/order/remove", {
            ouid: row.ouid
          }).then(res => {
            if (res.status == 200 && res.data.code) {
              this.$message.success({
                message: res.data.msg,
                duration: 1500,
                showClose: true
              });
            } else {
              this.$message.error({
                message: res.data.msg,
                duration: 1500,
                showClose: true
              });
            }
          });
          this.loadDataList();
        }).catch(() => {});
      },
      handleStatusUpdated(index, row) {
        this.tableData[index].status = row.status;
        this.tableData[index].statusmemo = row.statusmemo;
      },
      handleStatusEdit(index, row) {
        this.statusVisible = true;
        this.$nextTick(() => {
          this.$refs.statusUI.dialogVisible = true;
          this.$refs.statusUI.init(index, JSON.parse(JSON.stringify(row)));
        })
      },

      handleStatusEditCallback(index, status) {
        this.tableData[index].status = status;
      },
      handleDownload(index, attaches) {
        const link = document.createElement('a');
        link.href = attaches[0].url;
        link.setAttribute('download', attaches[0].name);
        link.click();

      },
      handleCancelOrder(index, row) {
        this.cancelVisible = true;
        this.$nextTick(() => {
          this.$refs.cancelOrderUI.dialogVisible = true;
          this.$refs.cancelOrderUI.init(index, JSON.parse(JSON.stringify(row)));
        })
      },
      handleExport() {
        if(this.selection.length>0){
          //导出选中项
            var index=1;
            let slist=this.selection.map((item)=>{
             let obj={
               "序号":index,
               "订单状态":item.status==0? '正常':'已取消',
               "下单日期":item.orderdate,
               "内部单号":item.ouid,
               "外部单号":item.ordercode,
               "订单类型":item.platformtype,
               "订单渠道":item.platform,
               "订单总额":item.sum_order,
               "应收总额":item.sum_platform,
               "应付总额":item.sum_sup,
               "订单备注":item.ordermemo,
               "收货人":item.buyerinfo.buyer,
               "收货电话":item.buyerinfo.mobile,
               "收货地址":item.buyerinfo.address,
               "收货单位名称":item.clientname,
               "实际客户":item.client,
               "业务员":item.saleman,
               "进项票状态":item.supticket_status==0?"待开具":"已开具",
               "进项发票号":item.supticket_ids.join(","),
               "进项发票备注":item.supticket_statusmemo,
               "销项发票状态":item.platformticket_status==1?"已开具":"待开具",
               "销项发票号":item.platformticket_ids.join(","),
               "认款状态":item.requestpay_status==0? "未认款":"已认款",
               "合作商":item.supname,
               "所属账套":item.account,
             }
             index++;
             return obj;
           });
           let ws= XLSX.utils.json_to_sheet(slist,{skipHeader:false});
              ws["!cols"]=[{wpx:80}];
              let wb=XLSX.utils.book_new();
              XLSX.utils.book_append_sheet(wb,ws,'销售订单');
              XLSX.writeFile(wb,"导出销售订单.xlsx");

        }else{
          if(this.filterData.daterange==""){
            this.$message.error({message:"请选择下单日期后再进行导出！",duration:1500,showClose:true});
            return;
          }
          let params = {
            daterange: this.filterData.daterange,
            curpage: this.curpage,
            pagesize: this.pagesize,
            ouid: this.filterData.ouid,
            ordercode: this.filterData.ordercode,
            buyerinfo: this.filterData.buyerinfo,
            good: this.filterData.good,
            platform: this.filterData.platform == "全部" ? "" : this.filterData.platform,
            supid: this.filterData.supid,
            commission_status: this.filterData.commission_status,
            ordermemo: this.filterData.ordermemo,
            client: this.filterData.client,
            account: this.filterData.account,
            clientname: this.filterData.clientname,
            saleticket_status: this.filterData.saleticket_status,
            saleticket_num: this.filterData.saleticket_num,
            supticketid: this.filterData.supticketid,
            clientticket_status: this.filterData.clientticket_status,
            clientticket_fphm: this.filterData.clientticket_fphm,
            income_status: this.filterData.income_status,
            paid_status: this.filterData.paid_tatus == "全部" ? "" : this.filterData.paid_tatus,
            supticket_status: this.filterData.supticket_status == "全部" ? "" : this.filterData.supticket_status,
            saleman: this.filterData.saleman,
            cost_bindstatus: this.filterData.cost_bindstatus,
            containcancel: this.filterData.containcancel ? 1 : 0
          }
          this.axios.post("/api/admin/order/export", params).then(res => {

              if(res.status==200 && res.data.code){
                index=1;
                 var slist=res.data.list.map((item)=>{
                   let obj={
                     "序号":index,
                     "订单状态":item.status==0? '正常':'已取消',
                     "下单日期":item.orderdate,
                     "内部单号":item.ouid,
                     "外部单号":item.ordercode,
                     "订单类型":item.platformtype,
                     "订单渠道":item.platform,
                     "订单总额":item.sum_order,
                     "应收总额":item.sum_platform,
                     "应付总额":item.sum_sup,
                     "订单备注":item.ordermemo,
                     "收货人":item.buyerinfo.buyer,
                     "收货电话":item.buyerinfo.mobile,
                     "收货地址":item.buyerinfo.address,
                     "收货单位名称":item.clientname,
                     "实际客户":item.client,
                     "业务员":item.saleman,
                     "进项票状态":item.supticket_status==0?"待开具":"已开具",
                     "进项发票号":item.supticket_ids,
                     "进项发票备注":item.supticket_statusmemo,
                     "销项发票状态":item.platformticket_status==1?"已开具":"待开具",
                     "销项发票号":item.platformticket_ids,
                     "认款状态":item.requestpay_status==0? "未认款":"已认款",
                     "合作商":item.supname,
                     "所属账套":item.account,
                   }
                   index++;
                   return obj;
                 });

                 let ws= XLSX.utils.json_to_sheet(slist,{skipHeader:false});
                    ws["!cols"]=[{wpx:80}];
                    let wb=XLSX.utils.book_new();
                    XLSX.utils.book_append_sheet(wb,ws,'销售订单');
                    XLSX.writeFile(wb,"导出销售订单.xlsx");

              }
            });

        }


        return;





      }
    }
  }
</script>

<style scoped>
  .table-fixed {
    ::v-deep .el-table__fixed-right {
      height: 100vh !important;
    }

    ::v-deep .el-table__fixed {
      height: 100% !important;
    }

  }

  .table-wraper {
    height: 350px;
  }
</style>
